/**
 * Copyright (c) 2019 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dao.VolunteerMapper;
import org.xstgongyi.eduaid.dataobject.VolunteerDO;

/**
 * @author oldcrane
 * @created 2019-04-24
 */
@Service
@CacheConfig(cacheNames = "volunteer")
public class VolunteerManager {

	@Autowired
	private VolunteerMapper dao;

	@CacheEvict(allEntries = true)
	public void insert(VolunteerDO volunteer) {
		dao.insert(volunteer);
	}

	@CacheEvict(allEntries = true)
	public void update(VolunteerDO volunteer) {
		dao.update(volunteer);
	}

	/**
	 * 调用者需确保参数不为null
	 */
	@Cacheable(key = "#id")
	public VolunteerDO getById(Integer id) {
		return dao.getById(id);
	}

	public List<VolunteerDO> listAll() {
		return dao.listAll();
	}

	/**
	 * 调用者需保证参数合法性，offset和limit为必填
	 */
	public List<VolunteerDO> listPage(Map<String, Object> condition) {
		return dao.listPage(condition);
	}

	/**
	 * 调用者需保证参数合法性
	 */
	public int countTotal(Map<String, Object> condition) {
		return dao.countTotal(condition);
	}

}
